﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.Serialization;

namespace JKF.Entities.Model
{
    /// <summary>
    /// 自定义异常，用于返回非系统错误，给与用户提示
    /// 最后修改时间2010-05-23
    /// </summary>
    public class MyException:Exception
    {
      
        string _showMessage = string.Empty;

        public string ShowMessage
        {
            get { return _showMessage; }
            set { _showMessage = value; }
        }

        #region "Member Variables"
        const string _className = "MyException";
		const int _hresult = -2146232832;
		#endregion	
	
		#region "Constructors"
		public MyException() : base()
		{
			base.HResult = _hresult;
		}
		
		public MyException(string message) 
			: base(message)
		{
            this._showMessage = message;
			base.HResult = _hresult;
		}
		
		public MyException(string message, Exception innerException) 
			: base(message, innerException)
		{
			base.HResult = _hresult;
		}

        protected MyException(SerializationInfo info, StreamingContext context) 
			: base(info, context)
		{
			base.HResult = _hresult;
		}
		#endregion		
		
		#region "Properties & Operators"
        public static implicit operator string(MyException ex)
		{
			return ex.ToString();
		}
		#endregion
		
		#region "Methods"
		public override string ToString()
		{
			StringBuilder sb = new StringBuilder();

			sb.AppendFormat("{0}: {1}", _className, this.Message);
			if (this.InnerException != null)
			{
				sb.AppendFormat(" ---> {0} <---", base.InnerException.ToString());
			}
	
			if (this.StackTrace != null)
			{
				sb.Append(Environment.NewLine);
				sb.Append(base.StackTrace);
			}

			return sb.ToString();
		}

		public override void GetObjectData(SerializationInfo info, StreamingContext context) 
		{ 
			base.GetObjectData (info, context); 
		} 

		#endregion
    }
}
